package Entity;

/**
 * This is an entity for a generic worker.
 * We have 4 kinds of workers: company manager, parking lot manager, parking lot worker and service class worker.
 * @author Sandra Krasko
 *
 */
public class Worker 
{
	private String workerID;
	private String FirstName;
	private String LastName;
	private String Email;
	private int workerNum;
	private Role r;
	private String password;
	private static int num=0;
	/**
	 * is an enum for the Role of the worker (company manager, parking lot manager, parking lot worker and service class worker)
	 */
	public enum Role {companyManager , parkingLotManager, parkingLotWorker, ServiceClassWorker};


	/**
	 * is the constructor. it will set the input from the user and also increase the "num" paramter that is like a time stamp for the worker.
	 * @param workerID = the worker id.
	 * @param FirstName= the first name.
	 * @param LastName= the last name.
	 * @param Email= the email.
	 * @param password= the password. 
	 * @param r= his role.
	 */
	public Worker(String workerID, String FirstName, String LastName, String Email, String password, Role r)
	{
		this.workerNum=num++;
		this.workerID=new String (workerID);
		this.FirstName=new String(FirstName);
		this.LastName=new String(LastName);
		this.password=new String (password);
		this.Email=new String(Email);
		this.r=r; 
	}
	/**
	 * is a validation function for the input of the user.
	 * @param workerID = the worker id.
	 * @param FirstName= the first name.
	 * @param LastName= the last name.
	 * @param Email= his email.
	 * @param password= his password.
	 * @param r= his role.
	 * @return true or false if every thing is ok.
	 */
	public boolean Validate(String workerID, String FirstName, String LastName, String Email, String password, Role r)
	{
		int i;
		boolean flag=false;
		char[] fn;
		char[] ln;
		Role [] kind=Role.values();
		
		if (workerID.length()!=9)
			return false;
		
		fn= new char [FirstName.length()];
		ln= new char [LastName.length()];
		fn=FirstName.toCharArray();
		ln=FirstName.toCharArray();
		
		for(i=0 ;i<FirstName.length(); i++)
		{
			if(fn[i]<'a'&&fn[i]>'z'||fn[i]<'A'&&fn[i]>'Z')
				return false;
		}
		
		for(i=0 ;i<LastName.length(); i++)
		{
			if(ln[i]<'a'&&ln[i]>'z'||ln[i]<'A'&&ln[i]>'Z')
				return false;
		}
		
		if(Email.indexOf('@')==-1 || Email.lastIndexOf('.')<Email.indexOf('@') || Email.startsWith("@"))
			return false;
		
		for(i=0; i<kind.length; i++)
		{
			if (r==kind[i])
			{
				flag=true;
				break;
			}
		}
		
		if (flag==false)
			return false;
		
	return true;	
	}
	
	// the get function.
	public String getEmail() {
		return Email;
	}
	
	public String getFirstName() {
		return FirstName;
	}
	
	public String getLastName() {
		return LastName;
	}
	public String getPassword() {
	return password;
	}
	
	public Role getR() {
		return r;
	}
	
	public String getWorkerID() {
		return workerID;
	}
	
	public int getWorkerNum() {
	return workerNum;
	}
	
	// the set function.
	public void setEmail(String email) {
		Email = email;
	}
	
	public void setFirstName(String firstName) {
		FirstName = firstName;
	}
	
	public void setLastName(String lastName) {
		LastName = lastName;
	}
	
	public void setPassword(String password) {
	this.password = password;
	}
	
	public void setR(Role r) {
	this.r = r;
	}
	
	public void setWorkerID(String workerID) {
	this.workerID = workerID;
	}
	
	public void setWorkerNum(int workerNum) {
	this.workerNum = workerNum;
	}	

}